package com.cskaoyan.service.impl;

import com.cskaoyan.mapper.MarketSystemMapper;
import com.cskaoyan.model.MarketSystem;
import com.cskaoyan.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author Pudding
 * @Date 2024/6/10 16:25
 */
@Service
public class SystemServiceImpl implements SystemService {
    @Autowired
    MarketSystemMapper systemMapper;

    @Override
    public Map<String, String> toMap() {
        //1. 查询数据库中全部记录，example条件为null
        List<MarketSystem> marketSystems = systemMapper.selectByExample(null);

        //2. 将List集合转换为Map集合
        //方式：通过流来进行
        Map<String, String> configMap = marketSystems.stream()
                .collect(Collectors.toMap(MarketSystem::getKeyName, MarketSystem::getKeyValue));

        //3. 返回map集合数据作为结果
        return configMap;
    }
}
